package rolesystem.middle.GUI;

import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;

import rolesystem.middle.parameters.DefaultParametersGUI;

public class StatePanel extends JScrollPane 
{
	private static final long serialVersionUID = 8133729542873545366L;
	private JEditorPane editorPane;
	public JScrollPane editorScrollPane;
	
	public StatePanel() 
	{	
		super();
		
		editorPane = createEditorPane();
		
		this.setViewportView(editorPane);         
		this.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		this.setPreferredSize(DefaultParametersGUI.STATE_PANEL_PREFERRED_SIZE);
		this.setMinimumSize(DefaultParametersGUI.STATE_PANEL_MINIMUM_SIZE);
	}
	
	
	private JEditorPane createEditorPane() 
	{
		JEditorPane editorPane = new JEditorPane();
		editorPane.setEditable(false);
		editorPane.setText("");
		
		return editorPane;
	}
	
	public synchronized void append(String s) 
	{
		try {
			Document doc = editorPane.getDocument();
			doc.insertString(doc.getLength(), s+System.getProperty("line.separator"), null);
		} catch(BadLocationException exc) {
			exc.printStackTrace();
		}
	}
	
	public void reset() 
	{
		editorPane.setText(null);
	}
	
}
